package com.cloud.config.security;
 
import com.alibaba.fastjson.JSON;
import com.cloud.utils.ResponseUtil;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
 
import java.io.IOException;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 您的权限不足，无法访问该资源
 * @author ian
 *
 */
public class IanAccessDeniedHandler implements AccessDeniedHandler {
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
    	response.setHeader("Content-Type", "application/json;charset=utf-8");
        response.getWriter().write(JSON.toJSONString(ResponseUtil.fail(403, "您的权限不足，无法访问该资源")));
        response.getWriter().flush();
    }
}